package com.gitee.sys.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.gitee.mybase.top.entity.SysResource;
import com.gitee.sys.service.ISysResourceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2018-11-17
 */
@RestController
@RequestMapping("/sys/sys-resource")
public class SysResourceController {

    @Reference
    private ISysResourceService sysResourceService;


   /* @GetMapping("/getMenuBar")
    @ApiOperation(value = "获菜单栏", notes = "获菜单栏", httpMethod = "GET")
    @ApiImplicitParam(name = "appCode", value = "app编码", paramType = "query", required = true, dataType = "String")
    public ResponseEntity<List<MenuBar>> getMenuBar(String appCode) {
        List<MenuBar> menuBars = sysResourceService.getMenuBar(appCode);
        for (MenuBar menuBar : menuBars) {
            List<Menu> menus = sysResourceService.getMenu(menuBar.getCode());
            for (Menu menu : menus) {
                menu.setMenuItemList(sysResourceService.getMenuItem(menu.getCode()));
            }
            menuBar.setMenuList(menus);
            menuBar.setMenuItemList(sysResourceService.getMenuItemByBar(menuBar.getCode()));
        }
        return ResponseEntity.ok(menuBars);
    }*/


    @PostMapping
    @ApiOperation(value = "新增系统资源", notes = "新增系统资源", httpMethod = "POST")
    public ResponseEntity<Void> saveResource(@RequestBody SysResource sysResource) {
        sysResourceService.saveResource(sysResource);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping
    @ApiOperation(value = "更新系统资源", notes = "更新系统资源", httpMethod = "PUT")
    public ResponseEntity<Void> updateResource(@RequestBody SysResource sysResource) {
        sysResourceService.updateResource(sysResource);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }

    @DeleteMapping
    @ApiOperation(value = "删除系统资源", notes = "删除系统资源", httpMethod = "DELETE")
    public ResponseEntity<Void> deletResource(@RequestParam String resourceCode) {
        sysResourceService.delResource(resourceCode);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }


}
